<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Section 4.5.4: Minimum spectral radius via Peron-Frobenius theory (GP)</title>
<link rel="canonical" href="/Users/mcgrant/Projects/CVX/examples/cvxbook/Ch04_cvx_opt_probs/html/min_spec_rad_ppl_dynamics.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Section 4.5.4: Minimum spectral radius via Peron-Frobenius theory (GP)</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Joelle Skaf - 01/29/06</span>
<span class="comment">% Updated to use CVX mode by Almir Mutapcic 02/08/06</span>
<span class="comment">%</span>
<span class="comment">% The goal is to minimize the spectral radius of a square matrix A</span>
<span class="comment">% which is elementwise nonnegative, Aij &gt;= 0 for all i,j. In this</span>
<span class="comment">% case A has a positive real eigenvalue lambda_pf (the Perron-Frobenius</span>
<span class="comment">% eigenvalue) which is equal to the spectral radius, and thus gives</span>
<span class="comment">% the fastest decay rate or slowest growth rate.</span>
<span class="comment">% The problem of minimizing the Perron-Frobenius eigenvalue of A,</span>
<span class="comment">% possibly subject to posynomial inequalities in some underlying</span>
<span class="comment">% variable x can be posed as a GP (for example):</span>
<span class="comment">%</span>
<span class="comment">%   minimize   lambda_pf( A(x) )</span>
<span class="comment">%       s.t.   f_i(x) &lt;= 1   for i = 1,...,p</span>
<span class="comment">%</span>
<span class="comment">% where matrix A entries are some posynomial functions of variable x,</span>
<span class="comment">% and f_i are posynomials.</span>
<span class="comment">%</span>
<span class="comment">% We consider a specific example in which we want to find the fastest</span>
<span class="comment">% decay or slowest growth rate for the bacteria population governed</span>
<span class="comment">% by a simple dynamic model (see page 166). The problem is a GP:</span>
<span class="comment">%   minimize   lambda</span>
<span class="comment">%       s.t.   b1*v1 + b2*v2 + b3*v3 + b4*v4 &lt;= lambda*v1</span>
<span class="comment">%              s1*v1 &lt;= lambda*v2</span>
<span class="comment">%              s2*v2 &lt;= lambda*v3</span>
<span class="comment">%              s3*v3 &lt;= lambda*v4</span>
<span class="comment">%              1/2 &lt;= ci &lt;= 2</span>
<span class="comment">%              bi == bi^{nom}*(c1/c1^{nom})^alpha_i*(c2/c2^{nom})^beta_i</span>
<span class="comment">%              si == si^{nom}*(c1/c1^{nom})^gamma_i*(c2/c2^{nom})^delta_i</span>
<span class="comment">%</span>
<span class="comment">% with variables bi, si, ci, vi, lambda.</span>

<span class="comment">% constants</span>
c_nom = [1 1]';
b_nom = [2 3 2 1]';
alpha = [1 1 1 1]'; beta  = [1 1 1 1]';
s_nom = [1 1 3]';
gamma = [1 1 1]'; delta = [1 1 1]';

cvx_begin <span class="string">gp</span>
  <span class="comment">% optimization variables</span>
  variables <span class="string">lambda</span> <span class="string">b(4)</span> <span class="string">s(3)</span> <span class="string">v(4)</span> <span class="string">c(2)</span>

  <span class="comment">% objective is the Perron-Frobenius eigenvalue</span>
  minimize( lambda )
  subject <span class="string">to</span>
    <span class="comment">% inequality constraints</span>
    b'*v      &lt;= lambda*v(1);
    s(1)*v(1) &lt;= lambda*v(2);
    s(2)*v(2) &lt;= lambda*v(3);
    s(3)*v(3) &lt;= lambda*v(4);
    [0.5; 0.5] &lt;= c; c &lt;= [2; 2];
    <span class="comment">% equality constraints</span>
    b == b_nom.*((ones(4,1)*(c(1)/c_nom(1))).^alpha).*<span class="keyword">...</span>
                ((ones(4,1)*(c(2)/c_nom(2))).^beta);
    s == s_nom.*((ones(3,1)*(c(1)/c_nom(1))).^gamma).*<span class="keyword">...</span>
                ((ones(3,1)*(c(2)/c_nom(2))).^delta);
cvx_end

<span class="comment">% displaying results</span>
disp(<span class="string">' '</span>)
<span class="keyword">if</span> lambda &lt; 1
  fprintf(1,<span class="string">'The fastest decay rate of the bacteria population is %3.2f.\n'</span>, lambda);
<span class="keyword">else</span>
  fprintf(1,<span class="string">'The slowest growth rate of the bacteria population is %3.2f.\n'</span>, lambda);
<span class="keyword">end</span>
disp(<span class="string">' '</span>)
fprintf(1,<span class="string">'The concentration of chemical 1 achieving this result is %3.2f.\n'</span>, c(1));
fprintf(1,<span class="string">'The concentration of chemical 2 achieving this result is %3.2f.\n'</span>, c(2));
disp(<span class="string">' '</span>)

<span class="comment">% construct matrix A</span>
A = zeros(4,4);
A(1,:) = b';
A(2,1) = s(1);
A(3,2) = s(2);
A(4,3) = s(3);

<span class="comment">% eigenvalues of matrix A</span>
disp(<span class="string">'Eigenvalues of matrix A are: '</span>)
eigA = eig(A)
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Successive approximation method to be employed.
   SDPT3 will be called several times to refine the solution.
   Original size: 49 variables, 11 equality constraints
   4 exponentials add 32 variables, 20 equality constraints
-----------------------------------------------------------------
 Cones  |             Errors              |
Mov/Act | Centering  Exp cone   Poly cone | Status
--------+---------------------------------+---------
  4/  4 | 3.713e+00  9.922e-01  0.000e+00 | Solved
  4/  4 | 1.366e-01  1.207e-03  0.000e+00 | Solved
  4/  4 | 5.510e-03  2.069e-06  0.000e+00 | Solved
  0/  2 | 2.329e-04  3.643e-09  0.000e+00 | Solved
-----------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.804067
 
 
The fastest decay rate of the bacteria population is 0.80.
 
The concentration of chemical 1 achieving this result is 0.50.
The concentration of chemical 2 achieving this result is 0.50.
 
Eigenvalues of matrix A are: 

eigA =

   0.8041 + 0.0000i
  -0.2841 + 0.0000i
  -0.0100 + 0.2263i
  -0.0100 - 0.2263i

</pre>
</div>
</body>
</html>